package com.ssm.juc.jvm;

import java.util.LinkedList;

public class Test1000 {

    public static void main(String[] args) throws InterruptedException {
        while (true) {
            Thread.sleep(1000);
        }
    }
}


class Solution1 {
    public String solve(String s) {
        StringBuilder lower = new StringBuilder();
        StringBuilder supper = new StringBuilder();
        char[] strArr = s.toCharArray();
        for (char item : strArr) {
            if (item >= 97 && item <= 122) {
                lower.append(item);
            } else {
                supper.append(item);
            }
        }
        return lower.toString() + supper;
    }
}

class Solution {
    public int solve(int[][] types, int[] nums, int kth) {
        int n = types.length;
        int m = nums.length;

        //1. 定义存放的数据结构
        LinkedList<Integer>[] buf = new LinkedList[n];
        for (int i = 0; i < n; i++) {
            buf[i] = new LinkedList<>();
        }
        int cnt = 0;
        //2. 遍历
        for (int i = 0; i < m; i++) {
            int idx = -1;
            for (int j = 0; j < n; j++) {
                if (buf[i].size() < types[j][1]) {
                    idx = j;
                    break;
                }
            }
            if (idx == -1) {
                int ans = pop(buf, types, n - 1);
                cnt++;
                if (cnt == kth) {
                    return ans;
                }
                for (int j = n - 1; j >= 1; j--) {
                    push(buf, types, j, pop(buf, types, j - 1));
                }
                push(buf, types, 0, nums[i]);
            } else {
                for (int j = idx; j >= 1; j--) {
                    push(buf, types, j, pop(buf, types, j - 1));
                }
                push(buf, types, 0, nums[i]);
            }
        }
        return -1;
    }

    public int pop(LinkedList<Integer>[] buf, int[][] types, int idx) {
        if (types[idx][0] == 0) {
            return buf[idx].removeLast();
        } else {
            return buf[idx].removeFirst();
        }
    }


    public void push(LinkedList<Integer>[] buf, int[][] types, int idx, int v) {
        buf[idx].addLast(v);
    }
}